package com.idealighter.game.dictionary.dic;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.dictionary.core.DictionaryTable;
import com.idealighter.game.dictionary.domain.RechargeItemDomain;
import com.idealighter.game.dictionary.mapper.RechargeItemMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Singleton
public class RechargeItemDic implements DictionaryTable<RechargeItemDomain> {

  private RechargeItemMapper mapper;
  private List<RechargeItemDomain> list;
  private Map<Integer, RechargeItemDomain> map;

  @Inject
  public RechargeItemDic(RechargeItemMapper mapper) {
    this.mapper = mapper;
    load();
  }

  @Override
  public List<RechargeItemDomain> list() {
    return list;
  }

  @Override
  public Map<Integer, RechargeItemDomain> map() {
    return map;
  }

  @Override
  public void load() {
    this.list = mapper.selectAll();
    Map<Integer, RechargeItemDomain> map = new HashMap<>();
    this.list.forEach(val -> {
      map.put(val.getId(), val);
    });
    this.map = map;
  }

  @Override
  public RechargeItemDomain get(int id) {
    return map.get(id);
  }
}
